package com.zstu.mall.web.user;

import com.zstu.mall.entity.ActivityColumn;
import com.zstu.mall.entity.ProductActivity;
import com.zstu.mall.entity.pojo.ResultBean;
import com.zstu.mall.service.ActivityColumnService;
import com.zstu.mall.service.ProductActivityService;
import com.zstu.mall.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ProductService productService;

    @Autowired
    private ProductActivityService productActivityService;

    @Autowired
    private ActivityColumnService activityColumnService;

    /**
     * 首页初始数据
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/column.do")
    public ResultBean<List<ActivityColumn>> getInitProduct() {
        List<ActivityColumn> activityColumns = new ArrayList<>();
        ActivityColumn activityColumn;
        ProductActivity productActivity;
        for(int i=1; i <= 7; i++){
            activityColumn = activityColumnService.get(Integer.toString(i));
            //处理活动栏目
            if(activityColumn.getStatus().equals("2")){
                productActivity = productActivityService.findByColumnId(activityColumn.getId());
                activityColumn.setProductActivity(productActivity);
            }
            //商品栏目默认不处理

            activityColumns.add(activityColumn);
        }
        return new ResultBean<>(activityColumns);
    }

}
